<?php

namespace App\Console\Commands\Tools\Camera;

use App\Kuafu\Shop\Model\CameraModel;
use App\Kuafu\Shop\Model\Shop;
use Illuminate\Console\Command;

class SyncCameraSupplyIdData extends Command
{
    protected $signature   = 'tools:sync-camera-supply-id';
    protected $description = '同步门店摄像头供应商 ID';

    public function handle()
    {
        // 同步悠络客
        Shop::query()
            ->where('ylkStoreId', '!=', 0)
            ->where('cameraSupplier', 0)
            ->get()
            ->each(function ($item) {
                $item->cameraSupplier   = CameraModel::SUPPLIER_YLK;
                $item->cameraSupplierId = $item->ylkStoreId;
                $item->save();
            });

        // 同步阿里云
        CameraModel::query()
                   ->where('deviceType', CameraModel::DEVICE_TYPE_CAMERA)
                   ->where('supplier', CameraModel::SUPPLIER_ALIYUN)
                   ->groupBy('shopId')
                   ->get()
                   ->each(function ($item) {
                       Shop::query()->where('id', $item->shopId)
                           ->update(['cameraSupplier' => CameraModel::SUPPLIER_ALIYUN]);
                   });

    }


}
